package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author guozh
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车
     *
     * @param shoppingCartDTO 购物车数据
     * @return Result
     */
    @PostMapping("/add")
    public Result<String> addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("购物车数据{}", shoppingCartDTO);
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success("添加购物车成功");
    }

    /**
     * 查看购物车数据
     *
     * @return Result<List < ShoppingCart>>
     */
    @GetMapping("/list")
    public Result<List<ShoppingCart>> findShoppingCartList() {
        log.info("查看购物车数据");
        return Result.success(shoppingCartService.findShoppingCartList());
    }

    /**
     * 清空购物车
     *
     * @return String
     */
    @DeleteMapping("/clean")
    public Result<String> cleanShoppingCartList() {
        log.info("清空购物车");
        shoppingCartService.cleanShoppingCartList();
        return Result.success();
    }

    /**
     * 删除的购物车
     * @param shoppingCartDTO 删除的购物车数据
     * @return Result<String>
     */
    @PostMapping("/sub")
    public Result<String> deleteShoppingCar(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("删除的购物车数据：{}", shoppingCartDTO);
        shoppingCartService.deleteShoppingCar(shoppingCartDTO);
        return Result.success();
    }
}
